"""
# ClaudeCodeTheory.jl

A comprehensive Julia package implementing the mathematical framework for AI-powered
code intelligence systems as described in the Claude Code theoretical foundations.

This package provides:
- POMDP-based formalization of code intelligence systems
- Multi-objective optimization for quality, latency, cost, and risk
- Contextual bandit algorithms for tool selection
- Hierarchical decision making with options framework
- Submodular optimization for context management
- Queueing theory models for concurrent execution
- Safety and risk assessment frameworks
- Performance evaluation and validation tools

## Modules

- `Core`: Fundamental types and abstractions
- `POMDP`: Partially Observable Markov Decision Process implementation
- `Tools`: Tool registry and execution framework
- `Learning`: Online learning algorithms (bandits, reinforcement learning)
- `Context`: Context selection and management
- `Concurrency`: Asynchronous execution and queueing models
- `Safety`: Risk assessment and verification
- `Evaluation`: Performance metrics and benchmarking
- `Visualization`: System monitoring and analysis tools

## Usage Example

```julia
using ClaudeCodeTheory

# Create a Claude Code system
system = ClaudeCodeSystem()

# Define a development task
task = CodeTask("implement sorting algorithm", "Python")

# Execute with optimal decision making
result = execute_task(system, task)
```

## References

Based on "Theoretical Foundations of Claude Code: Mathematical Models and 
Algorithmic Analysis of AI-Powered Code Intelligence Systems"
"""
module ClaudeCodeTheory

# Standard library imports
using LinearAlgebra
using Statistics
using Random
using Distributed
using Logging

# External package imports
using POMDPs
using POMDPModels
using ParticleFilters
using JuMP
using Optim
using Convex
using Distributions
using StatsBase
using DataStructures
using Graphs
using StaticArrays
using JSON3

# Include core modules
include("core/types.jl")
include("core/abstractions.jl")

# Include POMDP framework
include("pomdp/state_space.jl")
include("pomdp/action_space.jl")
include("pomdp/observations.jl")
include("pomdp/transitions.jl")
include("pomdp/rewards.jl")
include("pomdp/belief_state.jl")

# Include learning algorithms
include("learning/contextual_bandits.jl")
include("learning/thompson_sampling.jl")
include("learning/online_optimization.jl")

# Include context management
include("context/submodular_optimization.jl")
include("context/selection_algorithms.jl")
include("context/dynamic_management.jl")

# Include tool system
include("tools/registry.jl")
include("tools/execution.jl")
include("tools/concurrency.jl")

# Include hierarchical framework
include("learning/hierarchical_options.jl")

# Include concurrency models
include("concurrency/queueing_models.jl")
include("concurrency/message_queue.jl")
include("concurrency/load_balancing.jl")

# Include safety framework
include("safety/risk_assessment.jl")
include("safety/constraint_satisfaction.jl")
include("safety/verification.jl")

# Include evaluation tools
include("evaluation/metrics.jl")
include("evaluation/benchmarking.jl")
include("evaluation/validation.jl")

# Include visualization
include("visualization/monitoring.jl")
include("visualization/analysis.jl")

# Export main interfaces
export 
    # Core types from types.jl
    EnvironmentalState,
    FileSystemState,
    DependencyGraph,
    ProcessState,
    ToolConfiguration,
    ExternalEnvironment,
    Tool,
    ToolAction,
    SystemObservation,
    ContextState,
    BeliefState,
    QualityMetrics,
    RiskAssessment,
    ResourceMetrics,
    MultiObjectiveUtility,
    CodeTask,
    TaskResult,
    
    # Tool categories and safety levels
    ToolCategory,
    SafetyLevel,
    SAFE, LOW_RISK, MEDIUM_RISK, HIGH_RISK, DANGEROUS,
    FILE_TOOLS, SEARCH_TOOLS, EDIT_TOOLS, EXEC_TOOLS, TEST_TOOLS, BUILD_TOOLS, GIT_TOOLS, WEB_TOOLS,
    
    # Learning algorithms
    LinUCBAgent,
    ThompsonSamplingAgent,
    ContextFeatureExtractor,
    
    # Action space
    ClaudeCodeActionSpace,
    
    # State space functions
    create_initial_state,
    state_distance,
    
    # Action space functions
    create_action,
    estimate_action_cost,
    estimate_action_latency,
    action_risk_level,
    
    # Bandit functions
    select_arm,
    update_bandit!,
    get_regret_bound,
    
    # Feature extraction functions
    extract_features,
    normalize_features,
    update_normalization!,
    
    # Utility functions from abstractions.jl
    softmax,
    confidence_interval,
    pareto_dominates,
    pareto_frontier,
    normalize_vector,
    entropy,
    
    # Utility functions from types.jl
    utility_value,
    is_safe,
    total_risk,
    total_quality

# Package version
const VERSION = v"0.1.0"

"""
    ClaudeCodeTheory.greet()

Print a welcome message with package information.
"""
function greet()
    println("""
    ╔══════════════════════════════════════════════════════════════╗
    ║                     ClaudeCodeTheory.jl                      ║
    ║                                                              ║
    ║    Mathematical Framework for AI-Powered Code Intelligence   ║
    ║                         Version $(VERSION)                           ║
    ║                                                              ║
    ║    Implementing theoretical foundations with:                ║
    ║    • POMDP-based system modeling                            ║
    ║    • Multi-objective optimization                           ║
    ║    • Contextual bandit learning                             ║
    ║    • Hierarchical decision making                           ║
    ║    • Safety and verification                                ║
    ╚══════════════════════════════════════════════════════════════╝
    """)
end

end # module ClaudeCodeTheory